package ygflower.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import ygflower.dao.FlowerDao;
import ygflower.domain.Flower;

public class FlowerDetailController extends AbstractController{
	 public static String FlowerDetailView = "FlowerDetail";
	 public static String viewFlower = "flower";
	FlowerDao flowerDap;
    public void setFlowerDap(FlowerDao flowerDap) {
        this.flowerDap = flowerDap;
    }
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter(Flower.PropertyID);
		Flower flower = null;
		if(StringUtils.isNotBlank(id)){
			flower =  flowerDap.findById(Integer.parseInt(id));
		}
		ModelAndView modelAndView = new ModelAndView(FlowerDetailView);
		modelAndView.addObject(viewFlower, flower);
		return modelAndView;
	}
}
